package com.ruibang.glass.portal.controller;

import com.ruibang.glass.portal.entity.Computer;
import com.ruibang.glass.portal.service.ComputerService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


/**
 * <p>
 * 电脑设置状态信息 前端控制器
 * </p>
 *
 * @author wujie
 * @since 2020-08-06
 */
@RestController
@RequestMapping("/api/computer")
@Api(value="电脑设置状态信息接口",tags={"电脑设置状态信息操作接口"})
public class ComputerController {

    
    @Autowired
    private ComputerService computerService;

    /**
    * 通过id查询
    */
    @GetMapping("/getById/{id}")
    @ApiOperation(value="获取电脑设置信息",notes="获取电脑设置信息")
    public ResultBody getById(@PathVariable(value = "id") Integer id){
        return ResultBody.success(computerService.getById(id));
    }

    /**
    * 新增
    */
    @PostMapping("/save")
    @ApiOperation(value="新增电脑设置信息",notes="新增电脑设置信息")
    public ResultBody save(@RequestBody Computer computer){
        LocalDateTime now = LocalDateTime.now();
        computer.setCreateTime(now);
        computer.setUpdateTime(now);
        computerService.save(computer);
        return ResultBody.success();
    }

    /**
    * 通过id删除
    */
    @GetMapping("/deleteById/{id}")
    @ApiOperation(value="通过ID删除电脑设置信息",notes="通过ID删除电脑设置信息")
    public ResultBody delete(@PathVariable(value = "id") String ids){
        String[] idsStrs = ids.split(",");
        for (String id:idsStrs){
            computerService.removeById(Integer.parseInt(id));
        }
        return ResultBody.success();
    }

    /**
    * 修改
    */
    @PostMapping("/update")
    @ApiOperation(value="修改电脑设置信息",notes="修改电脑设置信息")
    public ResultBody updateById(@RequestBody Computer computer){
        computer.setUpdateTime(LocalDateTime.now());
        computerService.updateById(computer);
        return ResultBody.success();
    }


    @GetMapping("/getByMac/{mac}")
    @ApiOperation(value="获取电脑设置信息",notes="获取电脑设置信息")
    public ResultBody getByMac(@PathVariable(value = "mac") String mac){
        return ResultBody.success(computerService.getByMac(mac));
    }

}
